layui.use(['layer', 'form', 'jquery', 'table', 'laydate'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;
    var table = layui.table;
    var laydate = layui.laydate;

    laydate.render({
        elem: '#updateDate',
        type: 'date',
        trigger: 'click'
    });
    //加载表格数据
    getTable();

    function getTable() {
        $.ajax({
            url: '/courseJournal/getCourseJournal?type=2',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                tablereload(data.data);
            }
        });
    }

    //表格加载
    function tablereload(data) {
        table.render({
            elem: '#table',
            id: 'table',
            data: data,
            title: '课程历史价格详细',
            toolbar: '#toolbar',
            page: {
                limit: 10,
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: '首页',
                last: '尾页'
            },
            cols: [
                [
                    {type: 'checkbox'},
                    {
                        field: '', title: '序号', align: 'center', templet: function (data) {
                            return data.LAY_INDEX;
                        }
                    },
                    {field: 'courseId', title: '课程编号', align: 'center'},
                    {field: 'courseName', title: '课程名称', align: 'center'},
                    {field: 'coursePrice', title: '商品原价', align: 'center',templet:function (data) {
                        return "￥"+data.coursePrice;
                        }},
                    {field: 'courseNprice', title: '商品现价', align: 'center',templet:function (data) {
                        return "￥"+data.courseNprice;
                        }},
                    {field: 'updateDate', title: '操作时间', align: 'center'},
                ]
            ]
        });
    }

    //搜索
    form.on('submit(search)', function (data) {
        $.ajax({
            url: '/courseJournal/getCourseJournal?type=2',
            type: 'post',
            dataType: 'json',
            data: data.field,
            success: function (data) {
                tablereload(data.data);
            }
        });
    })
    //重置
    $('#reset').click(function () {
        $('input[name=courseId]').val('');
        $('input[name=courseName]').val('');
        $('input[name=updateDate]').val('');
        getTable();
    });
    //返回
    goBack = function goBack(){
        //跳转课程列表
        parent.$('#Jump').val('首页');
        parent.getQuick();
        return;
    }
});